package ch.epfl.lara.matcheck.util.printer


trait FormatterTrees[T] extends Formatter {
  
  
  protected def format(separator: String)(trees: List[T]): String = trees match {
    case Nil => ""
    case x :: Nil => format(x)
    case x :: xs => format(x) + separator + format(separator)(xs)
  }
  
  protected def concat(trees: List[T]): String  = format("")(trees)
  protected def comma(trees: List[T]): String   = format(", ")(trees)
  protected def newline(trees: List[T]): String = format("\n")(trees)
  protected def guard(tree: Option[T]): String  = optformat(" if ")(tree)
  
    
  protected def optformat(prefix: String)(tree: Option[T]): String = tree match {
    case None => ""
    case Some(term) => prefix + format(term)
  }
  
  protected def format(tree: T): String
  
  def toString(tree: T): String = format(tree) 
}
